package cn.zjh.system.controller;

import cn.zjh.basic.util.AjaxResult;
import cn.zjh.basic.util.PageList;
import cn.zjh.system.domain.Dictionarydetail;
import cn.zjh.system.query.DictionarydetailQuery;
import cn.zjh.system.service.IDictionarydetailService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RequestMapping("/dictionarydetail")
@RestController
public class DictionarydetailController {
    @Autowired
    private IDictionarydetailService iDictionarydetailService;

    @GetMapping
    public List<Dictionarydetail> findAll(){
        return iDictionarydetailService.findAll();
    }


    @GetMapping("/{id}")
    public List<Dictionarydetail> findOnea(@PathVariable("id") Long id){
        return iDictionarydetailService.findOnea(id);
    }

    @PostMapping
    public PageList<Dictionarydetail> queryData(@RequestBody DictionarydetailQuery dictionarydetailQuery){

        return iDictionarydetailService.queryPage(dictionarydetailQuery);
    }

    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        try {
            iDictionarydetailService.delete(id);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"删除失败");
        }
    }

    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody Dictionarydetail dictionarydetail ){
        try {
            if(dictionarydetail.getId() == null){
                iDictionarydetailService.save(dictionarydetail);
            }else {
                iDictionarydetailService.update(dictionarydetail);
            }
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();

            return new AjaxResult(false,"操作成功");
        }
    }


    @PatchMapping
    @ApiOperation(value = "批量删除")
    public AjaxResult patchDel(@RequestBody List<Long> ids){
        try {
            iDictionarydetailService.patchDel(ids);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"批量删除失败");
        }
    }
}
